package com.zpark.evaluate;

import com.zpark.entity.EvaluateData;
import com.zpark.entity.EvaluateReport;
import com.zpark.entity.HistoryData;
import com.zpark.entity.RiskFactor;

/**
 * 当天累计登录次数的评估
 */
public class TotalEvaluate extends Evaluate{
    private int countThreshold;//登录次数阈值
    public TotalEvaluate(int countThreshold) {
        super(RiskFactor.TOTAL);
        this.countThreshold = countThreshold;
    }

    @Override
    public void eval(EvaluateData evaluateData, HistoryData historyData, EvaluateReport evaluateReport, EvaluateChain evaluateChain) {

        //1. 评估
        Boolean isRisk = doEval(historyData.getCurrentDayLoginCount());
        evaluateReport.signReport(RiskFactor.TOTAL,isRisk);
        //2.继续
        evaluateChain.doChain(evaluateData, historyData, evaluateReport);
    }

    private Boolean doEval(Integer currentDayLoginCount) {
        if(currentDayLoginCount==null){
            currentDayLoginCount=0;
        }
        return !(countThreshold>currentDayLoginCount);
    }
}
